package com.jl.jlapp.service;

import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import android.widget.RemoteViews;

import com.jl.jlapp.R;
import com.jl.jlapp.mvp.activity.ScreenActivity;

import java.io.File;
import java.io.IOException;

public class DownloadService
        extends IntentService {
    private static final String EXTRA_VERSION = "version";
    private RemoteViews contentView;
    private NotificationCompat.Builder notificationCompatBuilder;
    private NotificationManagerCompat notificationManagerCompat;
    private int notification_id = 0;
    private PendingIntent pendingIntent;

    public DownloadService() {
        super("DownloadService");
    }

    private void createNotification() {
        this.contentView = new RemoteViews(getPackageName(), R.layout.layout_notification_download);
        this.contentView.setTextViewText(R.id.notificationTitle, getString(R.string.txt_downloading));
        this.contentView.setTextViewText(R.id.notificationPercent, "0%");
        this.contentView.setProgressBar(R.id.notificationProgress, 100, 0, false);
        Intent localIntent = new Intent(this, ScreenActivity.class);
        localIntent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
        this.pendingIntent = PendingIntent.getActivity(this, 0, localIntent, 0);
        this.notificationCompatBuilder = new NotificationCompat.Builder(this);
        this.notificationCompatBuilder.setSmallIcon(17301633).setTicker(getString(R.string.txt_downloading)).setContent(this.contentView).setContentIntent(this.pendingIntent).setOngoing(true).setWhen(System.currentTimeMillis());
        this.notificationManagerCompat = NotificationManagerCompat.from(this);
        this.notificationManagerCompat.notify(this.notification_id, this.notificationCompatBuilder.build());
    }

    private void download(File paramFile, String paramString)
            throws IOException {
//    URLConnection urlConnection =(HttpURLConnection)  new URL(paramString).openConnection();
//    paramString.setRequestMethod("GET");
//    paramString.setConnectTimeout(30000);
//    paramString.connect();
//    if (paramString.getResponseCode() != 200) {
//      throw new IOException(paramString.getResponseMessage());
//    }
//    int i = paramString.getContentLength();
//    InputStream localInputStream = paramString.getInputStream();
//    paramFile = new FileOutputStream(paramFile, false);
//    byte[] arrayOfByte = new byte['ࠀ'];
//    long l1 = 0L;
//    long l2 = System.currentTimeMillis();
//    for (;;)
//    {
//      int j = localInputStream.read(arrayOfByte);
//      if (j == -1) {
//        break;
//      }
//      paramFile.write(arrayOfByte, 0, j);
//      long l3 = l1 + j;
//      j = (int)(100L * l3 / i);
//      l1 = l3;
//      if (System.currentTimeMillis() - l2 > 500L)
//      {
//        this.contentView.setTextViewText(R.id.notificationPercent, j + "%");
//        this.contentView.setProgressBar(R.id.notificationProgress, 100, j, false);
//        this.notificationManagerCompat.notify(this.notification_id, this.notificationCompatBuilder.build());
//        l2 = System.currentTimeMillis();
//        l1 = l3;
//      }
//    }
//    this.contentView.setTextViewText(R.id.notificationPercent, "100%");
//    this.contentView.setProgressBar(R.id.notificationProgress, 100, 100, false);
//    this.notificationManagerCompat.notify(this.notification_id, this.notificationCompatBuilder.build());
//    paramFile.flush();
//    paramFile.close();
//    localInputStream.close();
//    paramString.disconnect();
    }

    public static void startService(Context paramContext, String paramString) {
        Log.d("aaaaaaaasetting", "startService");
        Intent localIntent = new Intent(paramContext, DownloadService.class);
        localIntent.putExtra("appUrl", paramString);
        paramContext.startService(localIntent);
    }

    protected void onHandleIntent(Intent paramIntent) {
//        Object localObject1;
//        if (paramIntent != null) {
//            localObject1 = paramIntent.getStringExtra("appUrl");
//            if (!SDCardUtils.isSDCardEnable()) {
//            }
//            FileUtils.createOrExistsDir(SDCardUtils.getSDCardPath() + "jlfood");
//            paramIntent = new File(SDCardUtils.getSDCardPath() + "jlfood", "jlfood.apk");
//        } else {
//            FileUtils.createFileByDeleteOldFile(paramIntent);
//            createNotification();
//            try {
//                download(paramIntent, (String) localObject1);
//                if (0 != 0) {
//                    new Handler(Looper.getMainLooper()).post(new Runnable() {
//                        public void run() {
//                            Toast.makeText(MyApplication.getInstance().getApplicationContext(), "下载新版本失败", Toast.LENGTH_SHORT).show();
//                        }
//                    });
//                    this.notificationManagerCompat.cancel(this.notification_id);
//                    paramIntent = new File(getCacheDir(), "jlfood.apk");
//                } else {
//                    localObject1 = new Intent("android.intent.action.VIEW");
//                    if (Build.VERSION.SDK_INT >= 24) {
//                        paramIntent = FileProvider.getUriForFile(this, "com.jl.jlapp.fileprovider", paramIntent);
//                        ((Intent) localObject1).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                        ((Intent) localObject1).addFlags(1);
//                        ((Intent) localObject1).setDataAndType(paramIntent, "application/vnd.android.package-archive");
//                    } else {
//                        startActivity((Intent) localObject1);
//                        this.notificationManagerCompat.cancel(this.notification_id);
//                        return;
//                        ((Intent) localObject1).setDataAndType(Uri.fromFile(paramIntent), "application/vnd.android.package-archive");
//                        ((Intent) localObject1).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    }
//                    Intent localIntent1;
//                    new Handler(Looper.getMainLooper()).post(new Runnable() {
//                        public void run() {
//                            Toast.makeText(MyApplication.getInstance().getApplicationContext(), "下载新版本失败", Toast.LENGTH_SHORT).show();
//                        }
//                    });
//                }
//            } catch (IOException localIOException) {
//                new Handler(Looper.getMainLooper()).post(new Runnable() {
//                    public void run() {
//                        Toast.makeText(MyApplication.getInstance().getApplicationContext(), "下载新版本失败", Toast.LENGTH_SHORT).show();
//                    }
//                });
//                this.notificationManagerCompat.cancel(this.notification_id);
//                return;
//                Intent intent = new Intent("android.intent.action.VIEW");
//                if (Build.VERSION.SDK_INT >= 24) {
//                    paramIntent = FileProvider.getUriForFile(this, "com.jl.jlapp.fileprovider", paramIntent);
//                    localIntent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    localIntent1.addFlags(1);
//                    localIntent1.setDataAndType(paramIntent, "application/vnd.android.package-archive");
//                } else {
//                    this.notificationManagerCompat.cancel(this.notification_id);
//                    localIntent1.setDataAndType(Uri.fromFile(paramIntent), "application/vnd.android.package-archive");
//                    localIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                }
//                startActivity(localIntent1);
//
//            } finally {
//
//            }
//        }
//        this.notificationManagerCompat.cancel(this.notification_id);
//        Intent localIntent2 = new Intent("android.intent.action.VIEW");
//        if (Build.VERSION.SDK_INT >= 24) {
//            paramIntent = FileProvider.getUriForFile(this, "com.jl.jlapp.fileprovider", paramIntent);
//            localIntent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            localIntent2.addFlags(1);
//            localIntent2.setDataAndType(paramIntent, "application/vnd.android.package-archive");
//        } else {
//            this.notificationManagerCompat.cancel(this.notification_id);
//            localIntent2.setDataAndType(Uri.fromFile(paramIntent), "application/vnd.android.package-archive");
//            localIntent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        }
//        startActivity(localIntent2);

    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/service/DownloadService.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */